package com.asj.vivo.lock.receiver;

import static com.asj.enums.DeviceIdentifierDictEnums.json_key_deviceCode;
import static com.asj.enums.HttpRequestDictEnums.receiveTimedTask;
import static com.asj.enums.ResultCodeEnums.result_error;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.asj.MainActivityService;
import com.asj.utils.HttpRequestUtils;
import com.asj.utils.JSONParamPackingUtils;
import com.google.gson.JsonObject;

/**
 * 监听开机广播，自动启动应用
 * */
public class BootCompleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // 启动服务
            Intent serviceIntent = new Intent(context, MainActivityService.class);
            //启动后台服务
            context.startForegroundService(serviceIntent);
            new Thread(()->{
                JsonObject errorRequestParam = new JsonObject();
                errorRequestParam.addProperty(json_key_deviceCode.getValue(), "123133123123123133123123");
                JSONParamPackingUtils.functionPacking(errorRequestParam,result_error,"监听开机广播生效");
                HttpRequestUtils.retryHttpRequest(receiveTimedTask.getValue(), errorRequestParam.toString(), 200, 3, null);
            }).start();
        }
    }
}